package com.easytouch.core.task;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by gulin on 2017/8/18.
 */

public abstract class Task implements Runnable {
    String mIdentifier = null;

    public String getIdentifier()
    {
        return mIdentifier;
    }
    public void setIdentifier(final String pIdentifier)
    {
        mIdentifier = pIdentifier;
    }

    public Task()
    {
    }

    public Task(final String pIdentifier)
    {
        setIdentifier(pIdentifier);
    }

    protected String read(InputStream in, int len) throws IOException {
        byte[] content = new byte[len];
        int readLen = in.read(content);
        int thisLen;
        if (readLen < len) {
            while (true) {
                thisLen = in.read(content, readLen - 1, len - readLen);
                if(thisLen == -1) break;
                readLen = thisLen + readLen;
                if (readLen >= len) break;
            }
        }

        return new String(content);
    }
}

